package android.cst.hqu.edu.cn.basemvp.mvp.View;

import android.cst.hqu.edu.cn.basemvp.R;
import android.cst.hqu.edu.cn.basemvp.mvp.Base.BaseActivity;
import android.cst.hqu.edu.cn.basemvp.mvp.Presenter.LoginContract;
import android.cst.hqu.edu.cn.basemvp.mvp.Presenter.LoginPresenter;
import android.cst.hqu.edu.cn.basemvp.mvp.VO.User;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends BaseActivity<LoginContract.ILoginView,LoginPresenter> implements LoginContract.ILoginView {

    private EditText edit_name,edit_password;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_layout);
        initViews();
    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter(this);
    }

    private void initViews(){
        edit_name=findViewById(R.id.edit_name);
        edit_password=findViewById(R.id.edit_password);
        Button btn_login = findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name= edit_name.getText().toString();
                String password=edit_password.getText().toString();
                User user=new User(name,password);
                getPresenter().login(user);
            }
        });
    }

    @Override
    public void showLoginResult(String str) {
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }
}
